﻿using B.S.BasicData.Api.Read.Application.Command.DepartmentTree;
using B.S.BasicData.Api.Read.DTOs;
using B.S.BasicData.Api.Read.Filters;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    /// <summary>
    /// 部门控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly IMediator mediator;

        public DepartmentController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 递归查询部门树数据
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>部门树数据</returns>
        [HttpGet]
        [AccessTokenFilter]
        public   Task<ApiResult<List<DepartmentTreeDTO>>> GetDepartmentTree([FromQuery]GetDepartmentTreeCommand request) { 
        return mediator.Send(request);
        }
    }
}
